﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MoPhongLapLich
{// con bo
    class Tracker:IAddQueue
    {
        
        private List<IAddQueue> _link;
        private List<Process> _processes; 
        private Timer _timer;


        public Tracker(Timer timer)
        {
            _timer = timer;
            _link = new List<IAddQueue>();
            
        }

        public List<Process> Processes
        {
            get { return _processes; }
            set { _processes = value; }
        }

        #region Implementation of IAddQueue

        public void Add(Process pro)
        {
            if(!pro.IsProcessing)
            {
                if (!pro.HasCycle())
                {
                    pro.IsProcessing = true;
                    Processes.Remove(pro);
                    if (Processes.Count == 0) _timer.Stop = true;
                }
                else
                {
                    pro.NextCycle();
                    foreach (var addQueue in _link)
                    {
                        addQueue.Add(pro);
                    }
                }
            }
            
        }

        #endregion

        

        public void AddLink(IAddQueue link)
        {
            _link.Add(link);
        }

        #region Implementation of ILink

        

        #endregion
    }
}
